import { message } from 'antd';
import * as qualityServices from '../services/quality';


export default {
  namespace: 'quality',
  state: {
    RelatedAnalysisData: [],
    // ReporterList: [],
    ProjectList: [],
  },
  reducers: { // 修改state
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
  effects: {
    // 获取统计数据
    *fetchPrjProcessData({ payload: { params } }, { call, put }) {
      const { data } = yield call(qualityServices.getPrjProcessData, params);// 接口调用
      yield put({
        type: 'save',
        payload: {
          RelatedAnalysisData: data.data || [], // 逻辑表达式，前面为空则用后面的值
        },
      });

    },
    // *fetchReporterList({ payload }, { call, put }) {
    //   const { data } = yield call(qualityServices.getReporterList);// 接口调用
    //   yield put({
    //     type: 'save',
    //     payload: {
    //       ReporterList: data.data || [], // 逻辑表达式，前面为空则用后面的值
    //     },
    //   });
    // },
    *fetchProjectList({ payload }, { call, put }) {
      const { data } = yield call(qualityServices.getProjectList);// 接口调用
      yield put({
        type: 'save',
        payload: {
          ProjectList: data.data.objects || [], // 逻辑表达式，前面为空则用后面的值
        },
      });
    },
    *clearQuaAnalysisData({payload},{call , put}){
      yield put({
        type: 'save',
        payload: {
          RelatedAnalysisData:  [], // 逻辑表达式，前面为空则用后面的值
        },
      });
    },
  },

  subscriptions: {
    setup({ dispatch, history }) {
      return history.listen(({ pathname }) => {
        if (pathname === '/prjmanage/prjchart') {
          // dispatch({ type: 'fetchReporterList' });
          dispatch({ type: 'fetchProjectList' });
          dispatch({type:'clearQuaAnalysisData'})
        }
        // dispatch({ type: 'fetchVersionPlan' });
      });
    },
  },
};
